<?php

class TemplateContext
{
	private $options;
	private $child_body;
	
	public function __construct(array $vars, $child_body=NULL)
	{
		$this->vars = $vars;
		$this->child_body = $child_body;
	}
	
	public function set($key, $value)
	{
		$this->vars[$key] = $value;
	}
	
	public function set_child_body($value)
	{
		$this->child_body = $value;
	}
	
	public function get($key)
	{
		// Return the value or an empty string
		return $this->vars[$key]?:'';
	}
	
	public function get_variables()
	{
		return array_keys($this->vars);
	}
	
	public function get_child_body()
	{
		return $this->child_body;
	}
	
	public static function merge(TemplateContext $one, TemplateContext $two)
	{
		$c = new TemplateContext(array());
		
		foreach (array($one, $two) as $given_context)
		{
			$vars = $given_context->get_variables();
			foreach ($vars as $key)
			{
				$c->set($key, $given_context->get($key));
			}
		}
		
		return $c;
	}
}

?>